﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading;
using System.Windows;
using System.Windows.Threading;
using Samurai.Infrastructure;
using System.Diagnostics;
using System.Net;

namespace Samurai.Client
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App
    {
        private void Application_Startup(object sender, StartupEventArgs e)
        {

        }

        private bool _exceptionFlag = false;

        private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
        {
            if (!_exceptionFlag)
            {
                _exceptionFlag = true;

                if (e.Exception is WebException || e.Exception.InnerException is WebException)
                {
                    //MessageBox.Show("Are you connected to the internet? Please Check!", "Information");
                    var v = 1;
                }

                else
                {
                    var exceptionReportDataContext = new ExceptionReportDataContext(e.Exception);

                    var window = new ExceptionReportWindow {DataContext = exceptionReportDataContext};

                    window.ShowDialog();
                }

                _exceptionFlag = false;
            }

            e.Handled = true;
        }
    }
}